using System.Windows.Data;
using System.Windows.Media;
using System.ComponentModel;

// Converts a boolean to a true/false value.
public class HighlightConverter : IValueConverter
{
	public object Convert(	object o, System.Type type, object parameter,
		System.Globalization.CultureInfo culture)
	{
		bool HighlightOn = (bool)o;

		if (HighlightOn)
		{
			switch (type.Name)
			{ case "Brush": return Brushes.White; break; }
		}
		else
		{
			switch (type.Name)
			{ case "Brush": return Brushes.Blue; break; }
		}

		return null;
	}

	public object ConvertBack(
      object o,
      System.Type type,
      object parameter,
      System.Globalization.CultureInfo culture)
    {
      return null;
    }
  }

// Stores the highlighted boolean and fires events when it changes.
public class MyData : IPropertyChange
{
	private bool highlighted;

	public MyData()
	{ highlighted = false;	// defaults to not highlighted	
	}

	public bool Highlighted
	{
		get { return highlighted; }
		set
		{
			if (highlighted != value)
			{
				highlighted = value;
				NotifyPropertyChanged("Highlighted");
			}
		}
	}

	// Declare event
	public event PropertyChangedEventHandler PropertyChanged;
	// NotifyPropertyChanged event handler to update property value in binding
	private void NotifyPropertyChanged(string info)
	{
		try
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(info));
		}
		catch { }
	}
}